package UF_SQLOBJ;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Example {
    public List<String> order() {
        final List<String> strings = new ArrayList<String>();
        populate(strings, 1, 3, 5, 7, 9);
        return strings;
    }

    public void populate(List<String> data, int... keys) {
        try {
            AutoCloseable ps = null;
            try {
                Connection conn = null;
                ps = conn.prepareStatement("SELECT * FROM Table where key=?");
                for (int key : keys) {
                    populate(data, key);
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } finally {
                ps.close();
            }
        } catch (Exception e) {
            // do nothing
        }
    }

    public void populate(List<String> data, int key) {
        PreparedStatement ps = null;
        try {
            ps.setInt(1, key);
            final ResultSet rs = ps.executeQuery();
            try {
                while (rs.next()) {
                    String s = rs.getString(1);
                    data.add(s);
                }
            } finally {
                rs.close();
            }
        } catch (SQLException e) {
            try {
                ps.close();
            } catch (SQLException e1) {
                // do nothing
            }
        }
    }
}
